

class AccMetric(object):
    """
        Softmax Accuracy Metric
    """

    def __init__(self, name):
        self.name = name
        self.sum_metric = 0.0
        self.n_inst = 0

    def update(self, val):
        self.sum_metric += val.item()
        self.n_inst += 1

    @property
    def avg(self):
        return self.sum_metric / self.n_inst

    @property
    def cur(self):
        return self.sum_metric


class LossMetric(object):
    """
        Loss Average Object
        update Tensor
        avg return int number
    """

    def __init__(self, name):
        self.name = name
        self.sum = 0.0
        self.n = 0

    def update(self, val):
        self.sum += val.item()
        self.n += 1

    @property
    def avg(self):
        return self.sum / self.n

    @property
    def cur(self):
        return self.sum
